package com.aaa.java06;

import com.aaa.utils.MyConstants;

import java.text.ParseException;
import java.util.Date;

/**
 * @author ：Teacher陈（86521760@qq.com）
 * @date ：Created in 2022/7/7 16:52
 * @description：工人类
 * @modified By：
 * @version: 1.0
 */
public class Worker {
    int  id;
    String name;
    /**
     * 上班时间
     */
    String  start;
    /**
     * 下班时间
     */
    String end;

    public Worker() {
    }

    public Worker(int id, String name, String start, String end) {
        this.id = id;
        this.name = name;
        this.start = start;
        this.end = end;
    }
    /**
     * @create by: Teacher陈（86521760@qq.com）
     * @description: 检查工作是否达到8小时
     * @create time: 2022/7/7 17:02
     * @param
     * @return void
     */
    public void  checkTime() throws ParseException {
        //8小时对应的毫秒数
        long workTime=8*60*60*1000;
        //将字符串的上班时间转换成date
       Date dateStart = DateTest.fromStringToDate(start, MyConstants.TIME_FORMAT);
       //将字符串的下班时间转换成date
       Date dateEnd = DateTest.fromStringToDate(end, MyConstants.TIME_FORMAT);
       //Date类型的下班时间转换成毫秒数
       long endTime = dateEnd.getTime();
        //Date类型的上班时间转换成毫秒数
       long startTime = dateStart.getTime();
       //计算工作时间的毫秒数
       long diff = endTime - startTime;
       //工作时间的毫秒数跟8小时的毫秒数比较
       if(diff>=workTime){
           System.out.println("可以下班");
       }else
       {
           System.out.println("工作不足八小时，继续干");
           System.out.println("还需要工作xxxx小时xx分xx秒");
       }
   }

    public static void main(String[] args) throws ParseException {
        Worker worker1= new Worker(1000,"张恒","2022-07-07 10:10:10","2022-07-07 17:30:10");
        worker1.checkTime();
    }
}
